package com.sunfeng.chap2.p13;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;

/**
 * @Author : 孙峰
 * @Description:
 * @Date : 2021/10/9  18:23
 */
public class Test13_23 {
    public static void main(String[] args) throws IOException, InterruptedException {
        RandomAccessFile randomAccessFile = new RandomAccessFile("D:\\nio\\a.txt", "rw");
        FileChannel channel = randomAccessFile.getChannel();

        System.out.println("begin" + System.currentTimeMillis());


        FileLock lock = channel.lock(0, Long.MAX_VALUE, false);
        System.out.println("end" + System.currentTimeMillis());

    }
}
